<?php

namespace Wechat\Services;

use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application;

class WechatService
{
    private static Application $app;

    /**
     *  APP
     *
     * @return Application
     */
    public static function app(): Application
    {
        self::$app ??= Factory::officialAccount(config('wechat'));
        return self::$app;
    }

    /**
     * 发送模板消息
     * 
     * @param string $touser
     * @param string $template_id
     * @param string|null $url
     * @param array $data
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function sendTemplateMessage(string $touser, string $template_id, ?string $url, array $data)
    {
        return self::app()->template_message->send([
            'touser' => $touser,
            'template_id' => $template_id,
            'url' => $url,
            'data' => $data,
        ]);
    }

    public static function test()
    {
        dump('test');
    }
}
